<template>
	<view class="content">
		<swiper class="swiperBox">
			<swiper-item class="swiperItem" v-for="(item,index) in data.thumb" :key="index">
				<image :src="item.url" class="swiperItem"></image>
			</swiper-item>
		</swiper>
		<text class="typeTitle">{{data.name}}</text>
		<view class="priceBox">
			<text class="price">￥{{data.price}}</text>
			<text class="have">已预约{{data.sale_num}}次</text>
		</view>
		<view class="foodBox" style="border-top: 25rpx solid #f0f0f0;">
			<text class="foodLabel">餐厅名称</text>
			<input type="text" class="foodInput" placeholder="请输入餐厅名称" v-model="restaurant"/>
		</view>
		<view class="foodBox">
			<text class="foodLabel">餐厅地址</text>
			<input type="text" class="foodInput" placeholder="请输入餐厅地址" v-model="address"/>
		</view>
		<view class="foodBox" style="border: none;flex-direction: column;align-items: baseline;">
			<text class="foodLabel">点餐菜品</text>
			<textarea v-model="foodName" placeholder="请输入菜品名称以/分割"  class="note" maxlength="10000"/>
		</view>
		<view class="orderTimeBox">
			<view class="titleBox">
				<text class="title">送餐时间</text>
				<view class="notBlock">
				</view>
				<text class="notLabel">不可预约</text>
				<view class="canBox">
				<view class="canBlock">
				</view>
				<text class="canLabel">已选择</text>
				</view>
			</view>
			<view class="dateBox">
				<text class="month">{{monthValue}}</text>
				<view class="triangle">
				</view>
				<view class="line">
				</view>
				<scroll-view class="dateScrollBox" scroll-x="true" :scroll-into-view="dateId">
					<view class="dateItem" :class="dateIndex==index?'dateActive':''"
						:id="`item-${index}`" v-for="(item,index) in dateArr" :key="index"
						@click="selDate(index)">
						{{item}}
					</view>
				</scroll-view>
				<uni-section class="selecteMonth">
					<uni-data-select v-mode="monthValue" :localdata="month" @change="changeMonth()" />
					</uni-data-select>
				</uni-section>
			</view>
			<view class="timeBox">
				<scroll-view class="timeScrollBox" scroll-x="true" :scroll-into-view="timeId">
					<view class="timeItem" :class="{'tiemActive': timeIndex === index,'timeDisable': !item.status}" :id="`item-${index}`"
						v-for="(item,index) in timeArr" :key="index" @click="selTime(index,item.status)">
						{{item.time_frame}}
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="commentBox">
			<view class="commentTop">
				<view class="commentLabel">
					评价
				</view>
				<view class="commentTotal">
					（{{comment.count}}条）
				</view>
				<view class="commentAll" @click="$navto.navto('/pages/service_evaluate/service_evaluate',{id:id})">
					全部 >
				</view>
			</view>
			<view class="commentItem" v-if="(comment.data || []).length > 0">
				<view class="userInfoBox">
					<image :src="comment.data[0].head" class="avatar"></image>
					<text class="name ellipsis">{{comment.data[0].name}}</text>
					<uni-rate disabled="true" :value="comment.data[0].score" size="18" color="#C4C4C4"
						activeColor="#000000" class="rate" />
				</view>
				<text class="commentInfo">{{comment.data[0].content}}</text>
				<view class="commentImgBox">
					<image :src="item.url" v-for="(item,index) in thumb" :key="index" class="commentImgItem"></image>
				</view>
			</view>
		</view>
		<view class="infoBox">
			<text class="infoLabel">服务详情</text>
			<mp-html :content="html" />
		</view>
		<view class="menuBox">
			<view class="left" @click="$switchTab('/pages/index/index')">
				<image :src="baseUrl+'img/index/home.png'" class="home"></image>
				<text class="homeLabel">首页</text>
			</view>
			<view class="center">
				<image :src="baseUrl+'img/service/service.png'" class="service"></image>
				<text class="serviceLabel">客服</text>
			</view>
			<view class="submit" @click="submit">
				立即下单
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				baseUrl: this.$baseUrl,
				foodName:'',
				restaurant:'',
				address:'',
				month: [],
				monthValue: '',
				value: 0,
				id: '',
				cat_id: '',
				data: '',
				timeArr: [], //可预约时段
				timeIndex: -1,
				time: '',
				service_data: '',
				dateArr: [],
				dateIndex: -1,
				date: '',
				yearArr: [],
				nextMonth: 0,
				dateId: '',
				timeId: '',
				comment:''
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.cat_id = options.cat_id;
			this.$request.get(`service_read/${this.id}`).then(res => {
				this.data = res.data.data;
			})
			this.dateArr = this.$getDateRanges().currentMonthDates //赋值当前月份剩余日期
			this.yearArr[0] = this.$getCurrentAndNextMonthYear().currentMonthYear;
			this.yearArr[1] = this.$getCurrentAndNextMonthYear().nextMonthYear;
			this.month = this.$getFormattedMonths();
			this.monthValue = this.month[0].text;
			this.service_data = this.yearArr[0] + '-' + this.dateArr[0].toString()
				.padStart(2, '0');
			this.getTime();
			this.$request.get(`evaluate_list?service_id=${this.id}`).then(res => { //获取评论
				this.comment = res.data;
			})
		},
		methods: {
			submit() {
				if (!this.restaurant) {
					return this.$toast('请输入餐厅名称');
				}
				if (!this.address) {
					return this.$toast('请输入餐厅地址');
				}
				if (!this.foodName) {
					return this.$toast('请输入菜品');
				}
				if (!this.date) {
					return this.$toast('请选择日期');
				}
				if (!this.time) {
					return this.$toast('请选择时间');
				}
				this.$store.commit('setTempData', this.$data);
				this.$navto.navto("/pages/service_food_submit/service_food_submit")
			},
			getTime() {
				this.$request.post(`time_frame_list`, {
					service_data: this.service_data,
					server_id: this.id
				}).then(res => {
					this.timeArr = res.data.data;
				})
			},
			// 选择时间
			selTime(index, status) {
				if (!status) {
					return this.$toast("当前时间不可选");
				}
				this.timeIndex = index;
				this.time = this.timeArr[index].time_frame;
			
			},
			// 选择日期
			selDate(index, status) {
				this.dateIndex = index;
				this.date = this.dateArr[index];
				this.dateArr = this.$getDateRanges().currentMonthDates;
				if (this.nextMonth == 0) {
					this.service_data = this.yearArr[0] + '-' + this.date.toString().padStart(2, '0');
				} else {
					this.service_data = this.yearArr[1] + '-' + this.date.toString().padStart(2, '0');
				}
				this.getTime();
			},
			// 选择月份
			changeMonth(e) {
				this.timeIndex = -1;
				this.dateIndex = -1;
				if (e == 0) { //当前月份
					this.nextMonth = 0;
					console.log(this.$getCurrentAndNextMonthYear().currentMonthYear);
					this.dateArr = this.$getDateRanges().currentMonthDates;
					this.service_data = this.yearArr[0] + '-' + this.dateArr[0].toString().padStart(2, '0');
				} else { //下个月
					this.nextMonth = 1;
					console.log(this.$getCurrentAndNextMonthYear().nextMonthYear);
					this.dateArr = this.$getDateRanges().nextMonthDates;
					this.service_data = this.yearArr[1] + '-' + this.dateArr[0].toString().padStart(2, '0');
				}
				console.log(this.nextMonth)
				this.monthValue = this.month[e].text;
				this.getTime();
				this.dateId = 'item-0';
				this.timeId = 'item-0';
				setTimeout(() => {
					this.dateId = '';
					this.timeId = '';
				}, 1000)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.menuBox {
		width: 100%;
		height: 130rpx;
		display: flex;
		position: fixed;
		bottom: 0rpx;
		// justify-content: space-between;
		margin-top: 40rpx;
		padding-top: 10rpx;
		border-top: 1rpx solid #cccccc;
		background-color: #FFFFFF;
		padding-left: 40rpx;
		padding-right: 40rpx;
		box-sizing: border-box;
		z-index: 1000;
		.submit {
			width: 480rpx;
			height: 80rpx;
			border-radius: 40rpx;
			background: #121212;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 700;
			font-size: 28rpx;
			color: #FFFFFF;
			letter-spacing: 5rpx;
			margin-left: auto;
		}

		.center {
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-left: 40rpx;

			.serviceLabel {
				font-weight: 500;
				font-size: 18rpx;
				color: #121212;
			}

			.service {
				width: 48rpx;
				height: 48rpx;
			}
		}

		.left {
			display: flex;
			flex-direction: column;
			align-items: center;

			.homeLabel {
				font-weight: 500;
				font-size: 18rpx;
				color: #121212;
			}

			.home {
				width: 48rpx;
				height: 48rpx;
			}
		}
	}

	.infoBox {
		padding: 70rpx 40rpx 150rpx 40rpx;
		display: flex;
		flex-direction: column;

		.infoLabel {
			font-weight: 700;
			width: 100%;
			text-align: center;
			font-size: 34rpx;
			color: #121212;
			letter-spacing: 5rpx;
			margin-bottom: 70rpx;
		}
	}

	.commentBox {
		width: 670rpx;
		margin-left: 40rpx;
		padding-top: 50rpx;
		padding-bottom: 50rpx;

		.commentItem {
			display: flex;
			flex-direction: column;
			margin-top: 65rpx;
			padding-bottom: 75rpx;
			border-bottom: 1rpx solid #121212;

			.commentImgBox {
				width: 590rpx;
				margin-left: 80rpx;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				/* 允许换行 */
				margin-top: 40rpx;

				.commentImgItem {
					width: 138rpx;
					height: 138rpx;
					margin-bottom: 10rpx;
					border-radius: 10rpx;
				}
			}

			.commentInfo {
				font-weight: 500;
				width: 590rpx;
				line-height: 48rpx;
				font-size: 24rpx;
				color: #121212;
				letter-spacing: 2rpx;
				margin-left: 80rpx;
			}

			.userInfoBox {
				display: flex;
				align-items: center;

				.rate {
					margin-left: auto;
				}

				.name {
					font-weight: 700;
					width: 400rpx;
					font-size: 24rpx;
					color: #121212;
					margin-left: 35rpx;
				}

				.avatar {
					width: 43rpx;
					height: 43rpx;
				}
			}
		}

		.commentTop {
			display: flex;
			align-items: center;
			padding-bottom: 45rpx;
			border-bottom: 1rpx solid #121212;

			.commentAll {
				font-weight: 500;
				font-size: 24rpx;
				color: #8E8E8E;
				margin-left: auto;
			}

			.commentTotal {
				font-weight: 500;
				font-size: 24rpx;
				color: #121212;
			}

			.commentLabel {
				font-weight: 700;
				font-size: 26rpx;
				color: #121212;
			}
		}
	}

.orderTimeBox {
		width: 750rpx;
		background: #ffffff;
		padding: 60rpx 40rpx 75rpx 40rpx;
		border-top: 25rpx solid #f0f0f0;
		border-bottom: 25rpx solid #f0f0f0;

		.timeBox {
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-top: 58rpx;

			.timeScrollBox {
				// width: 450rpx;
				overflow-x: scroll;
				display: flex;
				white-space: nowrap;

				.timeItem {
					// height: 50rpx;
					font-weight: 500;
					font-size: 26rpx;
					color: #121212;
					margin-right: 75rpx;
					flex: 0 0 auto;
					display: inline-flex;
				}

				.tiemActive {
					color: #FF6E5D;
					font-weight: 900;
					// border-bottom: 4rpx solid #FF6E5D;
				}

				.timeDisable {
					color: #8E8E8E;
				}
			}
		}

		.dateBox {
			position: relative;
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-top: 58rpx;
			padding-bottom: 58rpx;
			border-bottom: 1rpx solid #121212;

			.selecteMonth {
				position: absolute;
				left: 0rpx;
				width: 120rpx;
				height: 50%;
			}

			.dateScrollBox {
				// width: 450rpx;
				margin-left: 54rpx;
				display: flex;
				white-space: nowrap;
				overflow-x: scroll;

				.dateItem {
					width: 80rpx;
					height: 80rpx;
					border: 1rpx solid #121212;
					border-radius: 50%;
					// display: flex;
					display: inline-flex;
					font-weight: 500;
					font-size: 26rpx;
					color: #121212;
					align-items: center;
					justify-content: center;
					margin-right: 33rpx;
					flex: 0 0 auto;
					box-sizing: border-box;
				}

				.dateActive {
					background: #FF6E5D;
					// border: none;
					color: #ffffff;
					border: 1rpx solid #FF6E5D;
				}

				.dateDisable {
					background: #f0f0f0;
					border: none;
				}
			}

			.line {
				width: 1rpx;
				height: 44rpx;
				background: #c7c7c7;
				margin-left: 50rpx;
			}

			.triangle {
				width: 24rpx;
				height: 18rpx;
				background: #121212;
				clip-path: polygon(0 0, 100% 50%, 0 100%);
			}

			.month {
				width: 150rpx;
				text-align: center;
				font-weight: 700;
				font-size: 30rpx;
				color: #121212;
				white-space: nowrap;
			}
		}

		.titleBox {
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-bottom: 53rpx;
			border-bottom: 1rpx solid #121212;

			.title {
				font-weight: 700;
				font-size: 26rpx;
				color: #121212;
			}

			.notBlock {
				width: 17rpx;
				height: 17rpx;
				background: #f0f0f0;
				margin-left: 265rpx;
			}

			.notLabel {
				font-weight: 500;
				font-size: 20rpx;
				color: #8E8E8E;
				margin-left: 14rpx;
			}

			.canBox {
				display: flex;
				align-items: center;
				margin-left: auto;

				.canBlock {
					width: 17rpx;
					height: 17rpx;
					background: #FF6E5D;
				}

				.canLabel {
					font-weight: 500;
					font-size: 20rpx;
					color: #121212;
					margin-left: 14rpx;
				}
			}
		}
	}

	::v-deep .uni-select {
		border: none;
	}
::v-deep .uni-icons{
		display: none;
	}
	::v-deep .uni-select__input-box {
		opacity: 0 !important;
	}

	.foodBox {
		display: flex;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 40rpx;
		border-bottom: 1rpx solid #121212;
		// padding-top: 40rpx;
		box-sizing: border-box;
		.note {
			width: 100%;
			height: 200rpx;
			margin-top: 20rpx;
			font-size: 26rpx;
		}
		.foodLabel {
			font-weight: 700;
			font-size: 26rpx;
			color: #121212;
		}

		.foodInput {
			font-weight: 500;
			font-size: 26rpx;
			color: #121212;
			text-align: right;
		}
	}

	.priceBox {
		display: flex;
		width: 670rpx;
		margin-left: 40rpx;
		margin-top: 45rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-bottom: 40rpx;
		padding-top: 40rpx;
		border-top: 1rpx solid #8E8E8E;

		.have {
			font-weight: 500;
			font-size: 22rpx;
			color: #cccccc;
		}

		.price {
			font-weight: 700;
			font-size: 30rpx;
			color: #121212;
		}
	}

	.typeTitle {
		font-weight: 700;
		width: 670rpx;
		margin-left: 40rpx;
		font-size: 40rpx;
		color: #121212;
		margin-top: 50rpx;
		display: block;
	}

	.swiperBox {
		width: 750rpx;
		height: 600rpx;

		.swiperItem {
			width: 100%;
			height: 100%;
		}
	}

	.content {
		width: 100%;
		height: 100vh;
		overflow-x: hidden;
	}
</style>